home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 / Ham Radio 2000.iso / ham2000 / tcp_ip / ntp_src / diff.ntp next >
Text File  |  1992-04-03  |  26KB  |  762 lines

  1. *** /tmp/,RCSt1016606    Tue Jun 25 11:10:51 1991
  2. --- commands.h    Tue Jun 25 10:42:12 1991
  3. ***************
  4. *** 121,126 ****
  5. --- 121,129 ----
  6.   int donetrom __ARGS((int argc,char *argv[],void *p));
  7.   int nr_attach __ARGS((int argc,char *argv[],void *p));
  8.   
  9. + /* In ntpd.c: */
  10. + int dontp __ARGS((int argc, char *argv[], void *p));
  11.   /* In pc.c: */
  12.   int doshell __ARGS((int argc,char *argv[],void *p));
  13.   int doisat __ARGS((int argc,char *argv[],void *p));
  14. *** /tmp/,RCSt1016611    Tue Jun 25 11:10:53 1991
  15. --- config.c    Tue Jun 25 10:42:17 1991
  16. ***************
  17. *** 307,312 ****
  18. --- 307,315 ----
  19.   #ifdef    NRS
  20.       "nrstat",    donrstat,    0, 0, NULLCHAR,
  21.   #endif    /* NRS */
  22. + #ifdef NTP
  23. +     "ntp",        dontp,        0, 0, NULLCHAR,
  24. + #endif /* NTP */
  25.       "param",    doparam,    0, 2, "param <interface>",
  26.       "ping",        doping,        512, 2,
  27.       "ping <hostid> [<length> [<interval> [incflag]]]",
  28. ***************
  29. *** 440,446 ****
  30. --- 443,453 ----
  31.   
  32.   /* Functions to be called on each clock tick */
  33.   void (*Cfunc[])() = {
  34. + #ifdef NTP
  35. +     ntppctick,        /* PC and NTP specific stuff to keep time. */
  36. + #else  /* not NTP */
  37.       pctick,    /* Call PC-specific stuff to keep time */
  38. + #endif /* not NTP */
  39.       kbint,    /* Necessary because there's no hardware keyboard interrupt */
  40.       refiq,    /* Replenish interrupt pool */
  41.   #ifdef    ASY
  42. *** /tmp/,RCSt1016621    Tue Jun 25 11:10:57 1991
  43. --- internet.tl    Tue Jun 25 10:42:21 1991
  44. ***************
  45. *** 23,26 ****
  46.   +arpcmd.obj &
  47.   +arp.obj &
  48.   +arphdr.obj &
  49. ! +netuser.obj
  50. --- 23,39 ----
  51.   +arpcmd.obj &
  52.   +arp.obj &
  53.   +arphdr.obj &
  54. ! +netuser.obj &
  55. ! +ntpd.obj &
  56. ! +ntp_config.obj &
  57. ! +ntp_io.obj &
  58. ! +ntp_leap.obj &
  59. ! +ntp_loopfilter.obj &
  60. ! +ntp_pcclock &
  61. ! +ntp_peer.obj &
  62. ! +ntp_proto.obj &
  63. ! +ntp_restrict.obj &
  64. ! +ntp_timer.obj &
  65. ! +ntp_util.obj &
  66. ! +ntp_control.obj &
  67. ! +ntp_version.obj
  68. *** /tmp/,RCSt1016626    Tue Jun 25 11:11:00 1991
  69. --- makefile    Tue Jun 25 10:42:25 1991
  70. ***************
  71. *** 53,59 ****
  72.       ipcmd.obj ip.obj iproute.obj iphdr.obj \
  73.       icmpcmd.obj icmp.obj icmpmsg.obj icmphdr.obj \
  74.       arpcmd.obj arp.obj arphdr.obj \
  75. !     netuser.obj
  76.   
  77.   AX25=    ax25cmd.obj ax25user.obj ax25.obj \
  78.       axheard.obj lapbtime.obj \
  79. --- 53,62 ----
  80.       ipcmd.obj ip.obj iproute.obj iphdr.obj \
  81.       icmpcmd.obj icmp.obj icmpmsg.obj icmphdr.obj \
  82.       arpcmd.obj arp.obj arphdr.obj \
  83. !     netuser.obj \
  84. !     ntpd.obj ntp_config.obj ntp_io.obj ntp_leap.obj ntp_loopfilter.obj \
  85. !     ntp_pcclock.obj ntp_peer.obj ntp_proto.obj ntp_restrict.obj \
  86. !     ntp_timer.obj ntp_util.obj ntp_version.obj ntp_control.obj
  87.   
  88.   AX25=    ax25cmd.obj ax25user.obj ax25.obj \
  89.       axheard.obj lapbtime.obj \
  90. ***************
  91. *** 82,88 ****
  92.       pc100vec.obj eaglevec.obj hapnvec.obj \
  93.       scc.obj sccvec.obj \
  94.       pi.obj pivec.obj \
  95. !     pcgen.obj sw.obj stopwatch.obj arcnet.obj
  96.   
  97.   makelist.exe: makelist.obj getopt.obj
  98.       $(CC) $(MODEL) makelist.obj getopt.obj
  99. --- 85,92 ----
  100.       pc100vec.obj eaglevec.obj hapnvec.obj \
  101.       scc.obj sccvec.obj \
  102.       pi.obj pivec.obj \
  103. !     pcgen.obj sw.obj stopwatch.obj arcnet.obj \
  104. !     ntp_pc.obj
  105.   
  106.   makelist.exe: makelist.obj getopt.obj
  107.       $(CC) $(MODEL) makelist.obj getopt.obj
  108. ***************
  109. *** 241,247 ****
  110.   nrhdr.obj: nrhdr.c global.h mbuf.h ax25.h iface.h proc.h timer.h sockaddr.h lapb.h netrom.h nr4.h
  111.   nrs.obj: nrs.c global.h mbuf.h iface.h proc.h timer.h pktdrvr.h ax25.h sockaddr.h lapb.h nrs.h asy.h trace.h commands.h
  112.   pathname.obj: pathname.c global.h dirutil.h
  113. ! pc.obj: pc.c global.h mbuf.h proc.h timer.h iface.h internet.h session.h hardware.h ftpcli.h ftp.h telnet.h socket.h sockaddr.h cmdparse.h pc.h
  114.   pc100.obj: pc100.c global.h mbuf.h iface.h proc.h timer.h pktdrvr.h netuser.h pc100.h 8530.h ax25.h sockaddr.h lapb.h trace.h pc.h session.h hardware.h ftpcli.h ftp.h telnet.h
  115.   pi.obj: pi.c global.h mbuf.h iface.h proc.h timer.h pktdrvr.h netuser.h pi.h 8530.h ax25.h sockaddr.h lapb.h trace.h pc.h session.h hardware.h ftpcli.h ftp.h telnet.h ip.h internet.h devparam.h
  116.   pktdrvr.obj: pktdrvr.c global.h proc.h mbuf.h timer.h netuser.h enet.h iface.h arcnet.h ax25.h sockaddr.h lapb.h slip.h slhc.h ip.h internet.h tcp.h ip.h kiss.h ec.h arp.h trace.h pktdrvr.h config.h devparam.h
  117. --- 245,251 ----
  118.   nrhdr.obj: nrhdr.c global.h mbuf.h ax25.h iface.h proc.h timer.h sockaddr.h lapb.h netrom.h nr4.h
  119.   nrs.obj: nrs.c global.h mbuf.h iface.h proc.h timer.h pktdrvr.h ax25.h sockaddr.h lapb.h nrs.h asy.h trace.h commands.h
  120.   pathname.obj: pathname.c global.h dirutil.h
  121. ! pc.obj: pc.c global.h mbuf.h proc.h timer.h iface.h internet.h session.h hardware.h ftpcli.h ftp.h telnet.h socket.h sockaddr.h cmdparse.h pc.h config.h
  122.   pc100.obj: pc100.c global.h mbuf.h iface.h proc.h timer.h pktdrvr.h netuser.h pc100.h 8530.h ax25.h sockaddr.h lapb.h trace.h pc.h session.h hardware.h ftpcli.h ftp.h telnet.h
  123.   pi.obj: pi.c global.h mbuf.h iface.h proc.h timer.h pktdrvr.h netuser.h pi.h 8530.h ax25.h sockaddr.h lapb.h trace.h pc.h session.h hardware.h ftpcli.h ftp.h telnet.h ip.h internet.h devparam.h
  124.   pktdrvr.obj: pktdrvr.c global.h proc.h mbuf.h timer.h netuser.h enet.h iface.h arcnet.h ax25.h sockaddr.h lapb.h slip.h slhc.h ip.h internet.h tcp.h ip.h kiss.h ec.h arp.h trace.h pktdrvr.h config.h devparam.h
  125. ***************
  126. *** 293,296 ****
  127. --- 297,315 ----
  128.   udphdr.obj: udphdr.c global.h mbuf.h ip.h iface.h proc.h timer.h internet.h udp.h netuser.h
  129.   version.obj: version.c
  130.   wildmat.obj: wildmat.c global.h
  131. + ntp_config.obj: ntp_config.c global.h socket.h timer.h sockaddr.h ntp_types.h ntp_syslog.h ntp_fp.h ntp.h netuser.h udp.h iface.h internet.h ip.h
  132. + ntp_io.obj: ntp_io.c global.h mbuf.h iface.h netuser.h socket.h proc.h timer.h sockaddr.h udp.h internet.h ip.h ntp_types.h ntp_syslog.h ntp_fp.h ntp.h
  133. + ntp_leap.obj: ntp_leap.c global.h timer.h sockaddr.h ntp_types.h ntp_syslog.h ntp_fp.h ntp.h netuser.h udp.h iface.h internet.h ip.h
  134. + ntp_loopfilter.obj: ntp_loopfilter.c global.h sockaddr.h ntp_types.h ntp_syslog.h ntp_fp.h ntp.h netuser.h udp.h iface.h internet.h ip.h
  135. + ntp_pcclock.obj: ntp_pcclock.c global.h sockaddr.h timer.h ntp_types.h ntp_syslog.h ntp_fp.h
  136. + ntp_peer.obj: ntp_peer.c global.h sockaddr.h ntp_types.h ntp_syslog.h ntp_fp.h ntp.h netuser.h udp.h iface.h internet.h ip.h
  137. + ntp_proto.obj: ntp_proto.c global.h timer.h sockaddr.h ntp_types.h ntp_syslog.h ntp_fp.h ntp.h netuser.h udp.h iface.h internet.h ip.h
  138. + ntp_restrict.obj: ntp_restrict.c global.h sockaddr.h ntp_types.h ntp_syslog.h ntp_fp.h ntp.h netuser.h udp.h iface.h internet.h ip.h
  139. + ntp_timer.obj: ntp_timer.c global.h timer.h sockaddr.h ntp_types.h ntp_syslog.h ntp_fp.h ntp.h netuser.h udp.h iface.h internet.h ip.h
  140. + ntp_util.obj: ntp_util.c global.h sockaddr.h ntp_types.h ntp_syslog.h ntp_fp.h ntp.h netuser.h udp.h iface.h internet.h ip.h
  141. + ntpd.obj: ntpd.c global.h sockaddr.h ntp_types.h ntp_syslog.h ntp_fp.h ntp.h netuser.h udp.h iface.h internet.h ip.h
  142. + ntp_version.obj: ntp_version.c
  143. + ntp_control.obj: ntp_control.c ntp_control.h ntp_types.h ntp_syslog.h ntp_fp.h ntp.h
  144. + ntp_pc.obj: ntp_pc.asm
  145.   
  146. *** /tmp/,RCSt1016631    Tue Jun 25 11:11:04 1991
  147. --- pc.c    Tue Jun 25 10:42:40 1991
  148. ***************
  149. *** 1,6 ****
  150. --- 1,7 ----
  151.   /* OS- and machine-dependent stuff for IBM-PC running MS-DOS and Turbo-C
  152.    * Copyright 1991 Phil Karn, KA9Q
  153.    */
  154.   #include <stdio.h>
  155.   #include <conio.h>
  156.   #include <dir.h>
  157. ***************
  158. *** 13,19 ****
  159. --- 14,22 ----
  160.   #include <alloc.h>
  161.   #include <stdarg.h>
  162.   #include <bios.h>
  163. + #include <time.h>
  164.   #include "global.h"
  165. + #include "config.h"
  166.   #include "mbuf.h"
  167.   #include "proc.h"
  168.   #include "iface.h"
  169. ***************
  170. *** 23,28 ****
  171. --- 26,39 ----
  172.   #include "cmdparse.h"
  173.   #include "pc.h"
  174.   
  175. + #ifdef NTP
  176. + #include "ntp_types.h"
  177. + #include "ntp_fp.h"
  178. + /* New time keeping added for NTP.  */
  179. + l_fp NClock;
  180. + #endif /* NTP */
  181.   #define    CTLC    0x3
  182.   #define    DEL    0x7f
  183.   
  184. ***************
  185. *** 32,39 ****
  186.   FILE *Rawterm;
  187.   unsigned _stklen = 8192;
  188.   int Tick;
  189.   static int32 Starttime;    
  190. ! int32 Clock;
  191.   
  192.   /* This flag is set by setirq() if IRQ 8-15 is used, indicating
  193.    * that the machine is a PC/AT with a second 8259 interrupt controller.
  194. --- 43,51 ----
  195.   FILE *Rawterm;
  196.   unsigned _stklen = 8192;
  197.   int Tick;
  198. + int SavedTick;            /* timerproc puts the value of Tick here. */
  199.   static int32 Starttime;    
  200. ! int32 Clock;            /* Ticks since NOS started */
  201.   
  202.   /* This flag is set by setirq() if IRQ 8-15 is used, indicating
  203.    * that the machine is a PC/AT with a second 8259 interrupt controller.
  204. ***************
  205. *** 86,91 ****
  206. --- 98,114 ----
  207.       /* Link timer handler into timer interrupt chain */
  208.       chtimer(btick);
  209.   
  210. + #ifdef NTP
  211. +     /* Initialize the NTP clock from DOS. */
  212. + #define    JAN_1970    2208988800L    /* 1970 - 1900 in seconds */
  213. +     { time_t t;
  214. +       (void) time (&t);
  215. +       NClock.l_ui = (unsigned long)t;
  216. +       NClock.l_ui += JAN_1970;
  217. +       NClock.l_uf = 0;
  218. +     }
  219. + #endif /* NTP */
  220.       /* Find out what multitasker we're running under, if any */
  221.       chktasker();
  222.   
  223. ***************
  224. *** 287,292 ****
  225. --- 310,597 ----
  226.       Tick++;
  227.       psignal(&Tick,1);
  228.   }
  229. + #ifdef NTP
  230. + /* This should really be in the NTP source files, but it depends on the
  231. +  * hardware.
  232. +  */
  233. + /* Variables for adjtime().  In NTP timestamp fractional units. */
  234. + /* xntp recommends 500/hz as tickadj (in microseconds).  For the PC,
  235. +  * this is 27.5 usec.  Converting microseconds to NTP fractions we get:
  236. +  */
  237. + int32 tickadj = 0x0001ccbfL;
  238. + /* Storing adjust_time as a signed long in units of NTP fractions limits
  239. +  * us to a max of +- 1/2 second adjustment at any time.
  240. +  */
  241. + int32 adjust_time = 0;
  242. + /* Size of PC tick in ntp fractional units. */
  243. + int32 ntp_tick = 0x0e0f9776L;
  244. + #if 0                /* Now in ntp_pc.asm */
  245. + /* Called from the timer process on every tick.   timerproc() saves the value
  246. +  * of Tick in SavedTick, which is used here to make sure that we don't
  247. +  * lose time if several timer interrupts occur before any are serviced. 
  248. +  */
  249. + void
  250. + ntppctick()
  251. + {
  252. +     int32 adjust;
  253. +     /* Keep the old style clock going as well.  Note that the old
  254. +      * clock will not be corrected by any adjtime() calls.  */
  255. +     Clock += SavedTick;
  256. +     for (; SavedTick; SavedTick--)  {
  257. +         adjust = 0;
  258. +         if (adjust_time)  {
  259. +             if (adjust_time < 0)
  260. +                 adjust = max(-tickadj, adjust_time);
  261. +             else
  262. +                 adjust = min(tickadj, adjust_time);
  263. +             adjust_time -= adjust;
  264. +         }
  265. +         /* assert ((NTP_TICK + tickadj < 2**32) &&
  266. +          *         (NTP_TICK - tickadj > 0))
  267. +          * so that adjust will not wrap around or be negative.
  268. +          */
  269. +         adjust += ntp_tick;
  270. +         /* Add in the adjustment.  adjust > 0 at this point. */
  271. +         /* I should rewrite this in assembler... */
  272. +         L_ADDUF (&NClock, (unsigned long)adjust);
  273. +     }
  274. + }
  275. + #endif /* 0 */
  276. + /* Return tickadj in NTP fractional units. */
  277. + unsigned long
  278. + get_tickadj()
  279. + {
  280. +     return (unsigned long)tickadj;
  281. + }
  282. + /* Return size of a clock tick in NTP fractional units. */
  283. + unsigned long
  284. + get_tick()
  285. + {
  286. +     return ntp_tick;
  287. + }
  288. + /* adjtime takes an NTP fraction to be adjusted, and returns any
  289. +  * previous adjustment that hadn't completed.
  290. +  */
  291. + int32
  292. + adjtime (frac)
  293. + int32 frac;
  294. + {
  295. +     int32 old = adjust_time;
  296. +     adjust_time = frac;
  297. +     return old;
  298. + }
  299. + /* Tables for converting from "microticks" to NTP timestamps. */
  300. + unsigned long uticktotslo[256] = {
  301. +     0x00000000, 0x00000e10, 0x00001c1f, 0x00002a2f,
  302. +     0x0000383e, 0x0000464e, 0x0000545e, 0x0000626d,
  303. +     0x0000707d, 0x00007e8c, 0x00008c9c, 0x00009aac,
  304. +     0x0000a8bb, 0x0000b6cb, 0x0000c4da, 0x0000d2ea,
  305. +     0x0000e0f9, 0x0000ef09, 0x0000fd19, 0x00010b28,
  306. +     0x00011938, 0x00012747, 0x00013557, 0x00014367,
  307. +     0x00015176, 0x00015f86, 0x00016d95, 0x00017ba5,
  308. +     0x000189b5, 0x000197c4, 0x0001a5d4, 0x0001b3e3,
  309. +     0x0001c1f3, 0x0001d003, 0x0001de12, 0x0001ec22,
  310. +     0x0001fa31, 0x00020841, 0x00021650, 0x00022460,
  311. +     0x00023270, 0x0002407f, 0x00024e8f, 0x00025c9e,
  312. +     0x00026aae, 0x000278be, 0x000286cd, 0x000294dd,
  313. +     0x0002a2ec, 0x0002b0fc, 0x0002bf0c, 0x0002cd1b,
  314. +     0x0002db2b, 0x0002e93a, 0x0002f74a, 0x0003055a,
  315. +     0x00031369, 0x00032179, 0x00032f88, 0x00033d98,
  316. +     0x00034ba7, 0x000359b7, 0x000367c7, 0x000375d6,
  317. +     0x000383e6, 0x000391f5, 0x0003a005, 0x0003ae15,
  318. +     0x0003bc24, 0x0003ca34, 0x0003d843, 0x0003e653,
  319. +     0x0003f463, 0x00040272, 0x00041082, 0x00041e91,
  320. +     0x00042ca1, 0x00043ab1, 0x000448c0, 0x000456d0,
  321. +     0x000464df, 0x000472ef, 0x000480ff, 0x00048f0e,
  322. +     0x00049d1e, 0x0004ab2d, 0x0004b93d, 0x0004c74c,
  323. +     0x0004d55c, 0x0004e36c, 0x0004f17b, 0x0004ff8b,
  324. +     0x00050d9a, 0x00051baa, 0x000529ba, 0x000537c9,
  325. +     0x000545d9, 0x000553e8, 0x000561f8, 0x00057008,
  326. +     0x00057e17, 0x00058c27, 0x00059a36, 0x0005a846,
  327. +     0x0005b656, 0x0005c465, 0x0005d275, 0x0005e084,
  328. +     0x0005ee94, 0x0005fca3, 0x00060ab3, 0x000618c3,
  329. +     0x000626d2, 0x000634e2, 0x000642f1, 0x00065101,
  330. +     0x00065f11, 0x00066d20, 0x00067b30, 0x0006893f,
  331. +     0x0006974f, 0x0006a55f, 0x0006b36e, 0x0006c17e,
  332. +     0x0006cf8d, 0x0006dd9d, 0x0006ebad, 0x0006f9bc,
  333. +     0x000707cc, 0x000715db, 0x000723eb, 0x000731fb,
  334. +     0x0007400a, 0x00074e1a, 0x00075c29, 0x00076a39,
  335. +     0x00077848, 0x00078658, 0x00079468, 0x0007a277,
  336. +     0x0007b087, 0x0007be96, 0x0007cca6, 0x0007dab6,
  337. +     0x0007e8c5, 0x0007f6d5, 0x000804e4, 0x000812f4,
  338. +     0x00082104, 0x00082f13, 0x00083d23, 0x00084b32,
  339. +     0x00085942, 0x00086752, 0x00087561, 0x00088371,
  340. +     0x00089180, 0x00089f90, 0x0008ad9f, 0x0008bbaf,
  341. +     0x0008c9bf, 0x0008d7ce, 0x0008e5de, 0x0008f3ed,
  342. +     0x000901fd, 0x0009100d, 0x00091e1c, 0x00092c2c,
  343. +     0x00093a3b, 0x0009484b, 0x0009565b, 0x0009646a,
  344. +     0x0009727a, 0x00098089, 0x00098e99, 0x00099ca9,
  345. +     0x0009aab8, 0x0009b8c8, 0x0009c6d7, 0x0009d4e7,
  346. +     0x0009e2f6, 0x0009f106, 0x0009ff16, 0x000a0d25,
  347. +     0x000a1b35, 0x000a2944, 0x000a3754, 0x000a4564,
  348. +     0x000a5373, 0x000a6183, 0x000a6f92, 0x000a7da2,
  349. +     0x000a8bb2, 0x000a99c1, 0x000aa7d1, 0x000ab5e0,
  350. +     0x000ac3f0, 0x000ad200, 0x000ae00f, 0x000aee1f,
  351. +     0x000afc2e, 0x000b0a3e, 0x000b184e, 0x000b265d,
  352. +     0x000b346d, 0x000b427c, 0x000b508c, 0x000b5e9b,
  353. +     0x000b6cab, 0x000b7abb, 0x000b88ca, 0x000b96da,
  354. +     0x000ba4e9, 0x000bb2f9, 0x000bc109, 0x000bcf18,
  355. +     0x000bdd28, 0x000beb37, 0x000bf947, 0x000c0757,
  356. +     0x000c1566, 0x000c2376, 0x000c3185, 0x000c3f95,
  357. +     0x000c4da5, 0x000c5bb4, 0x000c69c4, 0x000c77d3,
  358. +     0x000c85e3, 0x000c93f2, 0x000ca202, 0x000cb012,
  359. +     0x000cbe21, 0x000ccc31, 0x000cda40, 0x000ce850,
  360. +     0x000cf660, 0x000d046f, 0x000d127f, 0x000d208e,
  361. +     0x000d2e9e, 0x000d3cae, 0x000d4abd, 0x000d58cd,
  362. +     0x000d66dc, 0x000d74ec, 0x000d82fc, 0x000d910b,
  363. +     0x000d9f1b, 0x000dad2a, 0x000dbb3a, 0x000dc94a,
  364. +     0x000dd759, 0x000de569, 0x000df378, 0x000e0188
  365. + };
  366. + unsigned long uticktotshi[256] = {
  367. +     0x00000000, 0x000e0f97, 0x001c1f2f, 0x002a2ec6,
  368. +     0x00383e5e, 0x00464df5, 0x00545d8d, 0x00626d24,
  369. +     0x00707cbc, 0x007e8c53, 0x008c9beb, 0x009aab82,
  370. +     0x00a8bb1a, 0x00b6cab1, 0x00c4da48, 0x00d2e9e0,
  371. +     0x00e0f977, 0x00ef090f, 0x00fd18a6, 0x010b283e,
  372. +     0x011937d5, 0x0127476d, 0x01355704, 0x0143669c,
  373. +     0x01517633, 0x015f85ca, 0x016d9562, 0x017ba4f9,
  374. +     0x0189b491, 0x0197c428, 0x01a5d3c0, 0x01b3e357,
  375. +     0x01c1f2ef, 0x01d00286, 0x01de121e, 0x01ec21b5,
  376. +     0x01fa314d, 0x020840e4, 0x0216507b, 0x02246013,
  377. +     0x02326faa, 0x02407f42, 0x024e8ed9, 0x025c9e71,
  378. +     0x026aae08, 0x0278bda0, 0x0286cd37, 0x0294dccf,
  379. +     0x02a2ec66, 0x02b0fbfe, 0x02bf0b95, 0x02cd1b2c,
  380. +     0x02db2ac4, 0x02e93a5b, 0x02f749f3, 0x0305598a,
  381. +     0x03136922, 0x032178b9, 0x032f8851, 0x033d97e8,
  382. +     0x034ba780, 0x0359b717, 0x0367c6ae, 0x0375d646,
  383. +     0x0383e5dd, 0x0391f575, 0x03a0050c, 0x03ae14a4,
  384. +     0x03bc243b, 0x03ca33d3, 0x03d8436a, 0x03e65302,
  385. +     0x03f46299, 0x04027231, 0x041081c8, 0x041e915f,
  386. +     0x042ca0f7, 0x043ab08e, 0x0448c026, 0x0456cfbd,
  387. +     0x0464df55, 0x0472eeec, 0x0480fe84, 0x048f0e1b,
  388. +     0x049d1db3, 0x04ab2d4a, 0x04b93ce2, 0x04c74c79,
  389. +     0x04d55c10, 0x04e36ba8, 0x04f17b3f, 0x04ff8ad7,
  390. +     0x050d9a6e, 0x051baa06, 0x0529b99d, 0x0537c935,
  391. +     0x0545d8cc, 0x0553e864, 0x0561f7fb, 0x05700792,
  392. +     0x057e172a, 0x058c26c1, 0x059a3659, 0x05a845f0,
  393. +     0x05b65588, 0x05c4651f, 0x05d274b7, 0x05e0844e,
  394. +     0x05ee93e6, 0x05fca37d, 0x060ab315, 0x0618c2ac,
  395. +     0x0626d243, 0x0634e1db, 0x0642f172, 0x0651010a,
  396. +     0x065f10a1, 0x066d2039, 0x067b2fd0, 0x06893f68,
  397. +     0x06974eff, 0x06a55e97, 0x06b36e2e, 0x06c17dc6,
  398. +     0x06cf8d5d, 0x06dd9cf4, 0x06ebac8c, 0x06f9bc23,
  399. +     0x0707cbbb, 0x0715db52, 0x0723eaea, 0x0731fa81,
  400. +     0x07400a19, 0x074e19b0, 0x075c2948, 0x076a38df,
  401. +     0x07784876, 0x0786580e, 0x079467a5, 0x07a2773d,
  402. +     0x07b086d4, 0x07be966c, 0x07cca603, 0x07dab59b,
  403. +     0x07e8c532, 0x07f6d4ca, 0x0804e461, 0x0812f3f9,
  404. +     0x08210390, 0x082f1327, 0x083d22bf, 0x084b3256,
  405. +     0x085941ee, 0x08675185, 0x0875611d, 0x088370b4,
  406. +     0x0891804c, 0x089f8fe3, 0x08ad9f7b, 0x08bbaf12,
  407. +     0x08c9beaa, 0x08d7ce41, 0x08e5ddd8, 0x08f3ed70,
  408. +     0x0901fd07, 0x09100c9f, 0x091e1c36, 0x092c2bce,
  409. +     0x093a3b65, 0x09484afd, 0x09565a94, 0x09646a2c,
  410. +     0x097279c3, 0x0980895a, 0x098e98f2, 0x099ca889,
  411. +     0x09aab821, 0x09b8c7b8, 0x09c6d750, 0x09d4e6e7,
  412. +     0x09e2f67f, 0x09f10616, 0x09ff15ae, 0x0a0d2545,
  413. +     0x0a1b34dd, 0x0a294474, 0x0a37540b, 0x0a4563a3,
  414. +     0x0a53733a, 0x0a6182d2, 0x0a6f9269, 0x0a7da201,
  415. +     0x0a8bb198, 0x0a99c130, 0x0aa7d0c7, 0x0ab5e05f,
  416. +     0x0ac3eff6, 0x0ad1ff8e, 0x0ae00f25, 0x0aee1ebc,
  417. +     0x0afc2e54, 0x0b0a3deb, 0x0b184d83, 0x0b265d1a,
  418. +     0x0b346cb2, 0x0b427c49, 0x0b508be1, 0x0b5e9b78,
  419. +     0x0b6cab10, 0x0b7abaa7, 0x0b88ca3e, 0x0b96d9d6,
  420. +     0x0ba4e96d, 0x0bb2f905, 0x0bc1089c, 0x0bcf1834,
  421. +     0x0bdd27cb, 0x0beb3763, 0x0bf946fa, 0x0c075692,
  422. +     0x0c156629, 0x0c2375c1, 0x0c318558, 0x0c3f94ef,
  423. +     0x0c4da487, 0x0c5bb41e, 0x0c69c3b6, 0x0c77d34d,
  424. +     0x0c85e2e5, 0x0c93f27c, 0x0ca20214, 0x0cb011ab,
  425. +     0x0cbe2143, 0x0ccc30da, 0x0cda4072, 0x0ce85009,
  426. +     0x0cf65fa0, 0x0d046f38, 0x0d127ecf, 0x0d208e67,
  427. +     0x0d2e9dfe, 0x0d3cad96, 0x0d4abd2d, 0x0d58ccc5,
  428. +     0x0d66dc5c, 0x0d74ebf4, 0x0d82fb8b, 0x0d910b22,
  429. +     0x0d9f1aba, 0x0dad2a51, 0x0dbb39e9, 0x0dc94980,
  430. +     0x0dd75918, 0x0de568af, 0x0df37847, 0x0e0187de
  431. + };
  432. + #if 0                /* Now in ntp_pc.asm */
  433. + /* getntptimeofday:  Returns the current time as an NTP timestamp. */
  434. + void
  435. + getntptimeofday (ts)
  436. + l_fp *ts;            /* return value */
  437. + {
  438. +     /* Copied and adapted from msclock() */
  439. +     int32 hi;
  440. +     int16 lo;
  441. +     int ticks;
  442. +     int32 bits;
  443. +     if(!Isat)  {
  444. +         *ts = NClock;
  445. +         return;
  446. +     }
  447. +     /* Make sure that a clock tick doesn't happen while we're
  448. +      * grabbing the clock bits.
  449. +      */
  450. +     do {
  451. +         hi = Clock + Tick + SavedTick;
  452. +         *ts = NClock;
  453. +         bits = clockbits();
  454. +         lo = bits;
  455. +         ticks = Tick + SavedTick + (bits >> 16);
  456. +     } while(hi != Clock + Tick + SavedTick);
  457. +     lo = -lo;        /* lo counts *down* */
  458. +     /* Convert to NTP fractional unit by table lookup. */
  459. +     hi = uticktotslo[lo & 0xff];
  460. +     hi += uticktotshi[lo >> 8];
  461. +     /* Again, I should maybe write this in assembler... */
  462. +     L_ADDUF (ts, hi);
  463. +     
  464. +     /* Adjust the time stamp as best I can for any yet-unprocessed
  465. +      * clock ticks by adding in the nominal tick value.
  466. +      */
  467. +     while (ticks--)  {
  468. +         L_ADDUF (ts, (unsigned long)ntp_tick);
  469. +     }
  470. + }
  471. + #endif /* 0 */
  472. + /* Step the time by ts.  */
  473. + void
  474. + stepntptime (ts)
  475. + l_fp *ts;
  476. + {
  477. +     /* Don't have to disable interrupts here since NClock is not
  478. +      * mucked with at interrupt level.
  479. +      */
  480. +     L_ADD(&NClock, ts);
  481. + }
  482. + /* Function to set DOS time to NTP time.  Called on exit
  483. +  * (and maybe hourly as well)
  484. +  */
  485. + void
  486. + setdostime()
  487. + {
  488. +     time_t t = (time_t)(NClock.l_ui - JAN_1970);
  489. +     stime (&t);
  490. + }
  491. + #else  /* not NTP */
  492.   /* Called from the timer process on every tick. NOTE! This function
  493.    * can NOT be called at interrupt time because it calls the BIOS
  494.    */
  495. ***************
  496. *** 305,310 ****
  497. --- 610,616 ----
  498.       oldt = t;
  499.       Clock = (days * 0x1800b0) + t - Starttime;
  500.   }
  501. + #endif /* not NTP */
  502.   
  503.   /* Set bit(s) in I/O port */
  504.   void
  505. ***************
  506. *** 551,558 ****
  507.   int32
  508.   msclock()
  509.   {
  510. !     int32 hi;
  511. !     int16 lo;
  512.       int16 count[4];    /* extended (48-bit) counter of timer clocks */
  513.   
  514.       if(!Isat)
  515. --- 857,864 ----
  516.   int32
  517.   msclock()
  518.   {
  519. !     int32 hi, bits;
  520. !     int16 lo, ticks;
  521.       int16 count[4];    /* extended (48-bit) counter of timer clocks */
  522.   
  523.       if(!Isat)
  524. ***************
  525. *** 559,568 ****
  526.           return Clock * MSPTICK;
  527.   
  528.       do {
  529. !         hi = Clock + Tick;
  530. !         lo = clockbits();
  531. !     } while(hi != Clock + Tick);
  532.   
  533.       count[0] = 0;
  534.       count[1] = hi >> 16;
  535.       count[2] = hi;
  536. --- 865,878 ----
  537.           return Clock * MSPTICK;
  538.   
  539.       do {
  540. !         hi = Clock + Tick + SavedTick;
  541. !         bits = clockbits();
  542. !         lo = bits & 0xffff;
  543. !         ticks = bits >> 16;
  544. !     } while(hi != Clock + Tick + SavedTick);
  545.   
  546. +     hi += ticks;
  547.       count[0] = 0;
  548.       count[1] = hi >> 16;
  549.       count[2] = hi;
  550. ***************
  551. *** 575,582 ****
  552.   int32
  553.   secclock()
  554.   {
  555. !     int32 hi;
  556. !     int16 lo;
  557.       int16 count[4];    /* extended (48-bit) counter of timer clocks */
  558.   
  559.       if(!Isat)
  560. --- 885,892 ----
  561.   int32
  562.   secclock()
  563.   {
  564. !     int32 hi, bits;
  565. !     int16 lo, ticks;
  566.       int16 count[4];    /* extended (48-bit) counter of timer clocks */
  567.   
  568.       if(!Isat)
  569. ***************
  570. *** 583,591 ****
  571.           return (Clock * MSPTICK) / 1000L;
  572.   
  573.       do {
  574. !         hi = Clock + Tick;
  575. !         lo = clockbits();
  576. !     } while(hi != Clock + Tick);
  577.   
  578.       count[0] = 0;
  579.       count[1] = hi >> 16;
  580. --- 893,905 ----
  581.           return (Clock * MSPTICK) / 1000L;
  582.   
  583.       do {
  584. !         hi = Clock + Tick + SavedTick;
  585. !         bits = clockbits();
  586. !         lo = bits & 0xffff;
  587. !         ticks = bits >> 16;
  588. !     } while(hi != Clock + Tick + SavedTick);
  589. !     hi += ticks;
  590.   
  591.       count[0] = 0;
  592.       count[1] = hi >> 16;
  593. *** /tmp/,RCSt1016643    Tue Jun 25 11:11:09 1991
  594. --- pc.h    Tue Jun 25 10:42:42 1991
  595. ***************
  596. *** 70,76 ****
  597.   int16 longmul __ARGS((int16 multiplier,int n,int16 *multiplicand));
  598.   INTERRUPT nullvec __ARGS((void));
  599.   void uchtimer __ARGS((void));
  600. ! int16 clockbits __ARGS((void));
  601.   
  602.   /* In stopwatch.asm: */
  603.   void swstart __ARGS((void));
  604. --- 70,79 ----
  605.   int16 longmul __ARGS((int16 multiplier,int n,int16 *multiplicand));
  606.   INTERRUPT nullvec __ARGS((void));
  607.   void uchtimer __ARGS((void));
  608. ! int32 clockbits __ARGS((void));
  609. ! /* In ntp_pc.asm: */
  610. ! void ntppctick __ARGS((void));
  611.   
  612.   /* In stopwatch.asm: */
  613.   void swstart __ARGS((void));
  614. *** /tmp/,RCSt1016648    Tue Jun 25 11:11:11 1991
  615. --- pc.tl    Tue Jun 25 10:42:43 1991
  616. ***************
  617. *** 26,30 ****
  618.   +pivec.obj &
  619.   +pcgen.obj &
  620.   +sw.obj &
  621. ! +stopwatch.obj
  622.   
  623. --- 26,31 ----
  624.   +pivec.obj &
  625.   +pcgen.obj &
  626.   +sw.obj &
  627. ! +stopwatch.obj &
  628. ! +ntp_pc.obj
  629.   
  630. *** /tmp/,RCSt1016653    Tue Jun 25 11:11:13 1991
  631. --- pcgen.asm    Tue Jun 25 10:42:48 1991
  632. ***************
  633. *** 197,208 ****
  634.   ; the 8253 in the PC/XT lacks a command to read the OUTPUT pin...
  635.   ;
  636.   ; The PC's clock design is soooo brain damaged...
  637.       public    clockbits
  638.   clockbits    proc
  639. !     mov    al,0c2h    ; latch timer 0 count and status for reading
  640.       pushf
  641.       cli        ; make chip references atomic
  642.       out    43h,al    ; send latch command
  643.       in    al,40h    ; get status of timer 0
  644.       mov    bl,al    ; save status
  645. --- 197,225 ----
  646.   ; the 8253 in the PC/XT lacks a command to read the OUTPUT pin...
  647.   ;
  648.   ; The PC's clock design is soooo brain damaged...
  649. ! ;
  650. ! ; Clockbits is now defined to return a long, with the number of
  651. ! ; unhandled clock interrupts in the high word.  The pc can't really
  652. ! ; count unhandled interrupts, but we can check to see if there is a
  653. ! ; clock interrupt pending (which could be the case if interrupts are turned
  654. ! ; off), and return a 1 in the high word if this is the case.  We
  655. ! ; read the interrupt request register before and after reading the clock
  656. ! ; to make sure that the clock doesn't wrap around while we're reading
  657. ! ; it.
  658.       public    clockbits
  659.   clockbits    proc
  660. !     mov    al,0ah    ; 0ah tells 8259 to read the interrupt request reg.
  661.       pushf
  662.       cli        ; make chip references atomic
  663. +     out    20h,al    ; Request to read interrupt request register
  664. +     nop        ; settling delay
  665. +     nop        ; (eoi does this, so me too)
  666. +     nop
  667. +     in    al,20h    ; Actually get the IRR
  668. + @@1:
  669. +     mov    dl,al    ; save the IRR
  670. +     and    dl,1    ; Only care about bit zero.
  671. +     mov    al,0c2h    ; latch timer 0 count and status for reading
  672.       out    43h,al    ; send latch command
  673.       in    al,40h    ; get status of timer 0
  674.       mov    bl,al    ; save status
  675. ***************
  676. *** 209,215 ****
  677. --- 226,244 ----
  678.       in    al,40h    ; get lsb of count
  679.       mov    ah,al    ; save lsb
  680.       in    al,40h    ; get msb of count
  681. +     mov    cx,ax    ; Save the count since we'll need it later.
  682. +     mov    al,0ah    ; Now read the IRR again.
  683. +     out    20h,al
  684. +     nop
  685. +     nop
  686. +     nop
  687. +     in    al,20h
  688. +     and    al,1    ; only care about bit 0
  689. +     cmp    al,dl    ; Is the IRR the same as the first time around?
  690. +     jne    @@1    ; nope
  691.       popf        ; no more chip references
  692. +     mov    dh,0    ; Clear any garbage in the high byte of dx
  693. +     mov    ax,cx    ; get the count back from storage
  694.       and    bl,80h    ; we're only interested in the OUT bit
  695.       xchg    ah,al    ; ax = count in correct order
  696.       shr    ax,1    ; count /= 2
  697. *** /tmp/,RCSt1016658    Tue Jun 25 11:11:15 1991
  698. --- timer.c    Tue Jun 25 10:42:50 1991
  699. ***************
  700. *** 34,39 ****
  701. --- 34,40 ----
  702.           i_state = dirps();    /* Tick is modified by an interrupt */
  703.           while(Tick == 0)
  704.               pwait(&Tick);
  705. +         SavedTick = Tick;
  706.           Tick = 0;
  707.           restore(i_state);
  708.   
  709. *** /tmp/,RCSt1016665    Tue Jun 25 11:11:17 1991
  710. --- timer.h    Tue Jun 25 10:42:52 1991
  711. ***************
  712. *** 39,44 ****
  713. --- 39,45 ----
  714.   #define    run_timer(t)    ((t)->state == TIMER_RUN)
  715.   
  716.   extern int Tick;
  717. + extern int SavedTick;
  718.   extern void (*Cfunc[])();    /* List of clock tick functions */
  719.   
  720.   /* In timer.c: */
  721. ***************
  722. *** 53,57 ****
  723. --- 54,62 ----
  724.   /* In hardware.c: */
  725.   int32 msclock __ARGS((void));
  726.   int32 secclock __ARGS((void));
  727. + unsigned long get_tickadj();
  728. + unsigned long get_tick();
  729. + int32 adjtime __ARGS((int32));
  730. + void setdostime();
  731.   
  732.   #endif    /* _TIMER_H */
  733.